""" 
read switch 干簧管传感器
接线:
    DO --> GPIO26 : 
        无遮挡,DO输出低电平
        有遮挡,DO输出高电平
    VCC --> 5.0V
    GND --> GND

说明: 
"""

from machine import Pin
import time

read_pinNum = 26  # 光电传感器DO 输入
led_pinNum = 15  # LED端口
led_pin = None
count = 0

def irq_call_back(irq_pin):
    global count
    value = irq_pin.value()
    """  有遮挡,DO输出高电平 """
    if value == 1:
        led_pin.value(1)
        print(f"有遮挡 --- {count}")
    else:
        led_pin.value(0)
        print(f"无遮挡 +++ {count}")
    count += 1


# 程序入口
if __name__ == "__main__":
    read_pin = Pin(read_pinNum, Pin.IN, Pin.PULL_DOWN)  # 输出低电平
    led_pin = Pin(led_pinNum, Pin.OUT)  # 输出
    led_pin.value(0)
    read_pin.irq(trigger=Pin.IRQ_RISING, handler=irq_call_back)  # 上升沿触发
    while True:
        pass
